package com.chima.service.impl;
import java.util.List;
import org.hibernate.criterion.DetachedCriteria;
import com.chima.dao.JobDetailDao;
import com.chima.domain.Job;
import com.chima.domain.JobDetail;
import com.chima.domain.PageRequestBean;
import com.chima.domain.PageResponseBean;
import com.chima.service.JobDetailService;

public class JobDetailServiceImp implements JobDetailService {
	private JobDetailDao jobDetailDao;
	
	public JobDetailDao getJobDetailDao() {
		return jobDetailDao;
	}
	public void setJobDetailDao(JobDetailDao jobDetailDao) {
		this.jobDetailDao = jobDetailDao;
	}
	public PageResponseBean findJobDetail(PageRequestBean pageRequestBean) {
		int firstResult =(pageRequestBean.getPage()-1)*pageRequestBean.getLimit();
		int maxResults =pageRequestBean.getLimit();
		int total = jobDetailDao.findByTotalCount(pageRequestBean.getDate(),pageRequestBean.getDept());
		// 获取分页查询条件
		DetachedCriteria detachedCriteria = pageRequestBean.getCriteria();// 不一定存在
		List<JobDetail> jobDetails = jobDetailDao.findByCriteria(detachedCriteria, firstResult, maxResults);
		PageResponseBean pageResponseBean = new PageResponseBean();
		pageResponseBean.setRows(jobDetails);
		pageResponseBean.setTotal(total);
		return pageResponseBean;
	}
	public void saveJobDetail(JobDetail jobDetail) {
		jobDetailDao.save(jobDetail);
	}

	public void deleteJobDetailByjobId(int jobId) {
		List<JobDetail> jobDetails=jobDetailDao.findByJobId(jobId);
		for(JobDetail jobDetail :jobDetails){
			jobDetailDao.delete(jobDetail);
		}
	}
	public void updataJobDetail(List<JobDetail> jobDetail) {
		for(JobDetail j:jobDetail){
			jobDetailDao.update(j);
		}
	}
	public void deleteJobDetailById(int id) {
		jobDetailDao.delete(id);
	}
	public List<JobDetail> findJobDetailByEmpIdAndJob(int EmpId,Job job) {
		return jobDetailDao.findByEmpAndJob(EmpId, job);
		
	}
	public List<JobDetail> findJobDetailByJobId(int JobId) {
		return jobDetailDao.findByJobId(JobId);
	}
	public List<JobDetail> findJobDetailByStepAndJobId(int step,int jobId) {
		return (List<JobDetail>) jobDetailDao.findByStepAndJobId(step, jobId);
	}
	public JobDetail findJobById(int id) {
		return jobDetailDao.findById(id);
	}
	
	public List<JobDetail> findAll() {
		return jobDetailDao.findAll();
	}
	
	public List<JobDetail> findByDateAndDepart(String date,int depart) {
		return jobDetailDao.findByDateAndDepart(date, depart);
	}
	public void updateBatch(Double actualcore,double pingji,int id) {
		jobDetailDao.update(actualcore,pingji,id);
	}
	
	public void updataJobDetail(JobDetail jobDetail) {
		jobDetailDao.update(jobDetail);
		
	}
	public void updatePingji(Double pingji, int id) {
		jobDetailDao.updatepingji(pingji, id);
		
	}
	public List<JobDetail> findJobDetailByJobAndDate(String jobid, String date) {
		
		return jobDetailDao.findByJobAndStartDate(jobid, date);
	}
	public List<JobDetail> findJobDetailByJobAndStartDateAndDepart(String jobid,String date,int depart) {
		
		return jobDetailDao.findByJobAndDateAndDepart(jobid, date, depart);
	}
	public List<JobDetail> findBydata1(String date) {
		
		return jobDetailDao.findByDate1(date);
	}
	public List<JobDetail> findJobDetailByJobAndDepart(String jobid, int depart) {
		return jobDetailDao.findByJobAndDepart(jobid, depart);
	}
	public JobDetail findById(int id) {
		return jobDetailDao.findById(id);
	}
	public List<JobDetail> findJobDetailByEmpAndDateAndJob(int EmpId,String date, Job job) {
		return jobDetailDao.findByJobEmpAndDateAndJob(EmpId, date, job);
	}
	public List<JobDetail> findByweekJob(int empId,Job job,String state) {
		
		return jobDetailDao.findWeekJobdetai(empId, job,state);
	}
	public List<JobDetail> findXMJobDetailByEmpAndDateAndJob(int EmpId,	String date, Job job) {
	
		return jobDetailDao.findXMJobByJobEmpAndDateAndJob(EmpId, date, job);
	}
	public List<JobDetail> findJobDetailByEmpIdAndJobAndstateAndTastproty(int EmpId,	Job job, String state,int proty) {
		
		return jobDetailDao.findByEmpAndJobAndStateAndProty(EmpId, job, state, proty);
	}
	public List<JobDetail> findByDateAndDepartAndState(String date, int depart,String state) {
		
		return jobDetailDao.findByDateAndDeparAndState(date, depart, state);
	}
	public List<JobDetail> findCXJobDetailByEmpAndDateAndJob(int EmpId,String date, Job job) {
		return jobDetailDao.findCXJobByJobEmpAndDateAndJob(EmpId, date, job);
	}
	public List<JobDetail> findLXMJobDetailByEmpAndDateAndJob(int EmpId,String date, Job job, int tastpropty) {
		return jobDetailDao.findLXMJobByJobEmpAndDateAndJob(EmpId, date, job, tastpropty);
	}
	public PageResponseBean findCraetJobDetail(PageRequestBean pageRequestBean) {
		
		int firstResult =(pageRequestBean.getPage()-1)*pageRequestBean.getLimit();
		int maxResults =pageRequestBean.getLimit();
		int total = jobDetailDao.findcraettotal(pageRequestBean.getDate(),pageRequestBean.getDept());
		// 获取分页查询条件
		DetachedCriteria detachedCriteria = pageRequestBean.getCriteria();// 不一定存在
		List<JobDetail> jobDetails = jobDetailDao.findByCriteria(detachedCriteria, firstResult, maxResults);
		PageResponseBean pageResponseBean = new PageResponseBean();
		pageResponseBean.setRows(jobDetails);
		pageResponseBean.setTotal(total);
		return pageResponseBean;
	}
	public List<JobDetail> findCreatJobDetail(int EmpId, Job job, String state,int proty) {
		
		return jobDetailDao.findCeatJob(EmpId, job, state, proty);
	}
	public List<JobDetail> findCreatXMJobDetail(int EmpId, String date,Job job, int tastpropty) {
		
		return jobDetailDao.findCreatMJobByJobEmpAndDateAndJob(EmpId, date, job, tastpropty);
	}
	
	
}
